<template>
  <el-dialog v-myFullscreen title="货位选择" :visible.sync="visible" width="800px" top="5vh" append-to-body>
    <el-form :model="queryParams" ref="queryForm" :inline="true" >
      <el-form-item label="编号" prop="code">
        <el-input
          v-model="queryParams.code"
          placeholder="请输入编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row>
      <el-table  ref="table" :data="goodsList"  @selection-change="handleSelectionChange" height="260px" highlight-current-row cell-class-name="li_table">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="编号" align="center" prop="code" />
        <el-table-column label="名称" align="center" prop="name" />
        <el-table-column label="规格" align="center" prop="basicProductInfo.model" />
        <el-table-column label="所属仓库" align="center" prop="depotName" />
        <el-table-column label="存放物资" align="center" prop="materialIdName" />
      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-row>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" :disabled="clickDisabled"  @click="submit" >确 定</el-button>
      <el-button @click="visible = false">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
    import { listGoodsNoSelect} from "@/api/equipment/materials/goods";
    // import { listProductInfo} from "@/api/basic/productInfo/productInfo";
    export default {
        data() {
            return {
                clickDisabled:true,
                selectRow: null,
                // 遮罩层
                visible: false,
                // 选中数组值
                tables: [],
                // 总条数
                total: 0,
                // 货位表格数据
                goodsList: [],
                //选择的物资列表
                selectStockList:[],
                // 查询参数
                queryParams: {
                    pageNum: 1,
                    pageSize: 50,
                    code: null,
                    name: null,
                    type: null,
                    depotId: null,
                    recordId:null,
                    depotSpaceId: null,
                    materialId: null,
                    qrUrl: null
                },
                // 所属仓库
                depotOptions: [],
                depotSpaceOptions: [],
            };
        },
        created(){
            this.getList();
        },
        methods: {
            // 显示弹框
            show(depotId,recordId) {
                this.queryParams.depotId=depotId;
                this.queryParams.recordId=recordId;
                this.getList();
                this.visible = true;
            },
            //改变一页的数量
            handleSizeChange(val) {
                this.queryParams.pageNum = 1;
                this.queryParams.pageSize = val;
                this.getList();
            },
            //改变页码
            handleCurrentChange(val) {
                this.queryParams.pageNum = val;
                this.getList();
            },
            // 查询表数据
            getList() {
                this.loading = true;
                listGoodsNoSelect(this.queryParams).then(response => {
                    this.goodsList = response.rows;
                    this.total = response.total;
                    this.loading = false;
                });
            },
            /** 搜索按钮操作 */
            handleQuery() {
                this.queryParams.pageNum = 1;
                this.getList();
            },
            /** 重置按钮操作 */
            resetQuery() {
                this.resetForm("queryForm");
            },
            // 多选框选中数据
            handleSelectionChange(selection) {
                this.ids = selection.map(item => item.id)
                this.buttonStatus();
            },
            selectionChange(row) {
                this.selectRow=row;
                this.buttonStatus();
            },
            buttonStatus(){
                if(this.selectStockList==null){
                    this.clickDisabled=true;
                }else {
                    this.clickDisabled=false;
                }
            },
            /** 提交按钮 */
            submit() {
                this.$emit('childFn', this.ids);
                this.visible = false;
            },
        }
    };
</script>
